 <?php 
    include_once"../formCRUD/regin_categori.php"; 
    if (isset($_GET['param'])) {
       $donners= explode(';',$_GET['param']);
       
       for($i = 0; $i < sizeof($donners); ++$i){
          $table[strstr($donners[$i], '=', true)]=substr(strstr($donners[$i], '='),1);
    }
  
    }
               $message='';
                $ret = false;
		$img_blob = '';
		$img_nom = '';
		$img_taille = 0;
		$img_type = '';
		$taille_max = 250000;
		$mail_nonModifiable='disabled="disabled"';
                if(isset($_FILES['image'])){
		$ret = is_uploaded_file($_FILES['image']['tmp_name']);
              
                        $img_type = $_FILES['image']['type'];
			$img_nom = $_FILES['image']['name'];
                        $_SESSION['img_blob']=$_FILES['image']['tmp_name'];
                          $id_nom = md5(uniqid(rand(), true));
                          $type=substr(strstr($img_type, '/'),1);
                          $nom_image ="../images_Annonces/".$id_nom.".".$type;
                          $resultat = move_uploaded_file($_SESSION['img_blob'],$nom_image);
                $img_taille = $_FILES['image']['size'];}
		if(!$ret || $img_taille > $taille_max ||!$resultat ) {
                     
			 if($img_taille > $taille_max)$message="Probléme dans le transfert...";
                         else $message="image trop gros...";
			
		}
		else { 
		       $param='nom_image='. $nom_image.';vous_etes='.$_POST['vous_etes'].';type_annonce='.$_POST['type_annonce'].';nom='.$_POST['firstname'];
                       $param .=';prenom='.$_POST['prenom'].';mail='.$_POST['email'].';telephone='.$_POST['telephone'].';titreannonce='.$_POST['titreannonce'];
                       $param .=';texteannonce='.$_POST['texteannonce'].';prix='.$_POST['prix'].';categorie='.$_POST['categorie'].';region='.$_POST['region'];
                if(!isset($_SESSION['user']) && isset($_POST['email'])){
                    $_SESSION['mail_user']=$_POST['email'];
                    //$actino='index.php?page_id=Connexion&param='.$param;
                   echo '<script language="Javascript">
                    document.location.replace("./index.php?page_id=Connexion&param='.$param.'");
                    </script>';
                 }
                if(isset($_SESSION['user']) && isset($_POST['email'])){ 
                    echo '<script language="Javascript">document.location.replace("./index.php?page_id=action_annonce&param='.$param.'");</script>';
                  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Jquery Inline Form Validation Engine</title>
<link rel="stylesheet" href="/css/validationEngine.jquery.css" type="text/css" media="screen" title="no title" charset="utf-8" />
<link rel="stylesheet" href="/css/template.css" type="text/css" media="screen" title="no title" charset="utf-8" />
<script src="/jquery/jquery.min.js" type="text/javascript"></script>
<script src="/jquery/jquery.validationEngine-en.js" type="text/javascript"></script>
<script src="/jquery/jquery.validationEngine.js" type="text/javascript"></script>

		<!-- AJAX SUCCESS TEST FONCTION	
			<script>function callSuccessFunction(){alert("success executed")}
					function callFailFunction(){alert("fail executed")}
			</script>
		-->
		
		<script>	
		$(document).ready(function() {

			
			$("#formID").validationEngine()
		
			
			//$.validationEngine.loadValidation("#date")
			//alert($("#formID").validationEngine({returnIsValid:true}))
			//$.validationEngine.buildPrompt("#date","This is an example","error")	 		 // Exterior prompt build example
			//$.validationEngine.closePrompt(".formError",true) 							// CLOSE ALL OPEN PROMPTS
		});
		
		// JUST AN EXAMPLE OF CUSTOM VALIDATI0N FUNCTIONS : funcCall[validate2fields]
		function validate2fields(){
			if($("#firstname").val() =="" ||  $("#lastname").val() == ""){
				return false;
			}else{
				return true;
			}
		}
	</script>	
<title>Document sans titre</title>
</head>
<body>
    <form  class="formular" method="post" action="<?php if(isset($actino))echo $actino;?>" id="formID" enctype="multipart/form-data">
        <fieldset>
            <legend>Déposer une annonce</legend>
            <fieldset>
                <legend>User Region</legend>
                <span>Région:</span>
                <?php echo $select_region;?>
            </fieldset>
            <fieldset>
                <legend>Categorie Annonce</legend>
                <span>Categorie:</span>
                <?php echo $select_categori;?>
            </fieldset>
            <fieldset>
                <legend>Vous êtes</legend> 
                <label><input class="validate[required] radio" type="radio" name="vous_etes"  id="radio1" value="Particulier"/></label><span>Particulier</span>  
                <label><input class="validate[required] radio" type="radio" name="vous_etes"  id="radio2" value="Professionnel"/> </label><span>Professionnel<br/></span>
                <span>Votre nom</span> <label><input type="text" value="<?php if (isset($table['nom'])) echo $table['nom'];?>"  name="firstname" id="firstname" class="validate[required,length[0,40]] text-input"/><br/></label>
                <span>Votre prenom<br/></span><label> <input value="<?php if (isset($table['prenom'])) echo $table['prenom'];?>" type="text" name="prenom" id="prenom" class="validate[required,length[0,40]] text-input"/><br/></label>
                <span>Email<br/></span><label><input value="<?php if (isset($table['mail']) ||isset($_SESSION['user'])) echo $_SESSION['user'];?>" <?php if(isset($_SESSION['user']))echo $mail_nonModifiable;?>  class="validate[required,custom[email]] text-input" type="text" name="email" id="email" /><br/></label>
                <span>Telephone<br/></span><label><input value="<?php if (isset($table['telephone'])) echo $table['telephone'];?>" class="validate[required,custom[telephone]] text-input" type="text" name="telephone"  id="telephone"/>
                                      <input type="checkbox" name="telmasq" value="true"/> :Masquer le numéro de téléphone dans l'annonce.</label>
            </fieldset>
            <fieldset>
                <legend>Annonce</legend>
                <label>
                    <input  class="validate[required] radio" type="radio" name="type_annonce"  id="radio1"  value="Offres" />
                </label>
                <span>Offres</span> 
                <label>
                    <input class="validate[required] radio" type="radio" name="type_annonce"  id="radio2" value="Demandes" />
                </label>
                <span>Demandes<br/></span>
                <span>Titre de l'annonce: <br/></span>
                <label>
                    <input type="text" name="titreannonce" value="<?php if (isset($table['titreannonce'])) echo $table['titreannonce'];?>"  id="titreannonce" class="validate[required,length[0,80]] text-input"/><br/>
                </label>
                <span>Texte  de l'annonce: <br/></span>
                <label>
                    <textarea name="texteannonce"  class="validate[required,length[6,300]] text-input" id="texteannonce"><?php if (isset($table['texteannonce'])) echo $table['texteannonce'];?></textarea><br/>
                </label>
                <span>Prix: <br/></span>
                <label> 
                    <input value="<?php if (isset($table['prix'])) echo $table['prix'];?>" class="validate[required,custom[onlyNumber],length[1,7]] text-input" type="text" name="prix"  id="prix"  />Ouguiya<br/>
                </label>
                <span>Photo principale<br/> </span>
                <label>
                    <?php echo $message;?><input type="file" id="image" size="35" name="image"/><br/><br/><br/>
                </label>
                <span> <input class="submit" type="submit" value="Valider!"/></span>
            </fieldset>
        </fieldset>
    </form>
</body>
</html>